﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Profiling.CustomSampler
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Diagnostics;
using Unity.Profiling.LowLevel;
using Unity.Profiling.LowLevel.Unsafe;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Profiling
{
  /// <summary>
  ///   <para>Custom CPU Profiler label used for profiling arbitrary code blocks.</para>
  /// </summary>
  [NativeHeader("Runtime/Profiler/ScriptBindings/Sampler.bindings.h")]
  [NativeHeader("Runtime/Profiler/Marker.h")]
  [UsedByNativeCode]
  public sealed class CustomSampler : Sampler
  {
    internal static CustomSampler s_InvalidCustomSampler = new CustomSampler();

    internal CustomSampler()
    {
    }

    internal CustomSampler(IntPtr ptr) => this.m_Ptr = ptr;

    /// <summary>
    ///   <para>Creates a new CustomSampler for profiling parts of your code.</para>
    /// </summary>
    /// <param name="name">Name of the Sampler.</param>
    /// <param name="collectGpuData">Specifies whether this Sampler records GPU timings. If you want the Sampler to record GPU timings, set this to true.</param>
    /// <returns>
    ///   <para>CustomSampler object or null if a built-in Sampler with the same name exists.</para>
    /// </returns>
    public static CustomSampler Create(string name, bool collectGpuData = false)
    {
      IntPtr marker = ProfilerUnsafeUtility.CreateMarker(name, (ushort) 1, (MarkerFlags) (8 | (collectGpuData ? 256 : 0)), 0);
      return marker == IntPtr.Zero ? CustomSampler.s_InvalidCustomSampler : new CustomSampler(marker);
    }

    /// <summary>
    ///   <para>Begin profiling a piece of code with a custom label defined by this instance of CustomSampler.</para>
    /// </summary>
    /// <param name="targetObject"></param>
    [Conditional("ENABLE_PROFILER")]
    public void Begin() => ProfilerUnsafeUtility.BeginSample(this.m_Ptr);

    /// <summary>
    ///   <para>Begin profiling a piece of code with a custom label defined by this instance of CustomSampler.</para>
    /// </summary>
    /// <param name="targetObject"></param>
    [Conditional("ENABLE_PROFILER")]
    public void Begin(UnityEngine.Object targetObject)
    {
      ProfilerUnsafeUtility.Internal_BeginWithObject(this.m_Ptr, targetObject);
    }

    /// <summary>
    ///   <para>End profiling a piece of code with a custom label.</para>
    /// </summary>
    [Conditional("ENABLE_PROFILER")]
    public void End() => ProfilerUnsafeUtility.EndSample(this.m_Ptr);
  }
}
